<?php
class Ads_WidgetController extends Clu_Controller_Action_Widget
{
	
	public function init()
	{
		//require_once (APP_PATH.'/modules/ads/Model/Ads.php');
    	//require_once (APP_PATH . "/modules/admin/Model/Weight.php");
    	$this->mWeight = new admin_Model_Weight();
		$this->m = new ads_Model_Ads();
		parent::init();
	}
	
	public function displayAction()
    {
    	//now get all the content_id from this $widgetPositionId;
    	$data['widget_position_id'] = $this->widget['id'];
    	$currentItems = $this->mWeight->searchCurrentItemsByWidgetPositionId($data);
    	$contents = array();
		foreach ($currentItems as $item)
		{
			$contents[] = $this->m->getAdsData($item['content_id'], array('get_article' => 1));
		}
		foreach($contents as $val)
		{
			$metadata = unserialize($val['metadata']);
			if($metadata['region'] == 5)
				$results[] = $val;
			
		}
		if(isset($results))
			$this->viewParams['data'] = $results;
		
    }
    
    public function adsOfPlaceAction()
    {
    	//now get all the content_id from this $widgetPositionId;
    	$data['widget_position_id'] = $this->widget['id'];
    	$currentItems = $this->mWeight->searchCurrentItemsByWidgetPositionId($data);
    	$contents = array();
		foreach ($currentItems as $item)
		{
			$contents[] = $this->m->getAdsData($item['content_id'], array('get_article' => 1));
		}
		foreach($contents as $val)
		{
			$metadata = unserialize($val['metadata']);
			if($metadata['region'] == 4)
			{
				$results[] = $val;
			}
			
		}
		if(isset($results))
			$this->viewParams['data'] = $results;
    }
    
    public function adsOfEventAction()
    {
    	//now get all the content_id from this $widgetPositionId;
    	$data['widget_position_id'] = $this->widget['id'];
    	$currentItems = $this->mWeight->searchCurrentItemsByWidgetPositionId($data);
    	$contents = array();
		foreach ($currentItems as $item)
		{
			$contents[] = $this->m->getAdsData($item['content_id'], array('get_article' => 1));
		}
		foreach($contents as $val)
		{
			$metadata = unserialize($val['metadata']);
			if($metadata['region'] == 4)
			{
				$results[] = $val;
			}
			
		}
		if(isset($results))
			$this->viewParams['data'] = $results;
    }
    
    public function adsOfBlogAction()
    {
    	//now get all the content_id from this $widgetPositionId;
    	$data['widget_position_id'] = $this->widget['id'];
    	$currentItems = $this->mWeight->searchCurrentItemsByWidgetPositionId($data);
    	$contents = array();
		foreach ($currentItems as $item)
		{
			$contents[] = $this->m->getAdsData($item['content_id'], array('get_article' => 1));
		}
		//die_a($contents);
		foreach($contents as $val)
		{
			$metadata = unserialize($val['metadata']);
			if($metadata['region'] == 4)
			{
				$results[] = $val;
			}
			
		}
		if(isset($results))
			$this->viewParams['data'] = $results;
    }
}
?>